import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_demo/widget/buttons.dart';
import 'package:fluttertoast/fluttertoast.dart';

class AcademicInforScreen extends StatelessWidget {

  final GlobalKey _formKey = GlobalKey<FormState>();

  @override
  Widget build(BuildContext context) {

    var graduationTime = Padding(
      padding: const EdgeInsets.fromLTRB(64, 32, 64, 32),
      child: Container(
        padding: const EdgeInsets.symmetric(horizontal: 16),
        child: TextFormField(
          autofocus: true,
          decoration: const InputDecoration(
            labelText: '毕业时间',
            hintText: '您的毕业时间',
            border: InputBorder.none,
          ),
          validator: (value) {
            if (value!.trim().isEmpty) {
              return '毕业时间不能为空';
            } else if (value.trim().length > 20) {
              return '毕业时间超出最大长度';
            } else {
              return null;
            }
          },
        ),
        decoration: BoxDecoration(
          border: Border.all(color: Colors.black26, width: 1.0),
          borderRadius: BorderRadius.circular(5.0),
        ),
      ),
    );

    var academicPrograms = Padding(
      padding: const EdgeInsets.fromLTRB(64, 0, 64, 32),
      child: Container(
        padding: const EdgeInsets.symmetric(horizontal: 16),
        child: TextFormField(
          autofocus: true,
          decoration: const InputDecoration(
            labelText: '学历项目',
            hintText: '您的学历项目',
            border: InputBorder.none,
          ),
          validator: (value) {
            if (value!.trim().isEmpty) {
              return '学历项目不能为空';
            } else if (value.trim().length > 10) {
              return '学历项目超出最大长度';
            } else {
              return null;
            }
          },
        ),
        decoration: BoxDecoration(
          border: Border.all(color: Colors.black26, width: 1.0),
          borderRadius: BorderRadius.circular(5.0),
        ),
      ),
    );

    var academicLevel = Padding(
      padding: const EdgeInsets.fromLTRB(64, 0, 64, 32),
      child: Container(
        padding: const EdgeInsets.symmetric(horizontal: 16),
        child: TextFormField(
          autofocus: true,
          decoration: const InputDecoration(
            labelText: '学历水平',
            hintText: '您的学历水平',
            border: InputBorder.none,
          ),
          validator: (value) {
            if (value!.trim().isEmpty) {
              return '学历水平不能为空';
            } else if (value.trim().length > 10) {
              return '学历水平超出最大长度';
            } else {
              return null;
            }
          },
        ),
        decoration: BoxDecoration(
          border: Border.all(color: Colors.black26, width: 1.0),
          borderRadius: BorderRadius.circular(5.0),
        ),
      ),
    );

    var academicNature = Padding(
      padding: const EdgeInsets.fromLTRB(64, 0, 64, 32),
      child: Container(
        padding: const EdgeInsets.symmetric(horizontal: 16),
        child: TextFormField(
          autofocus: true,
          decoration: const InputDecoration(
            labelText: '学历性质',
            hintText: '您的学历性质',
            border: InputBorder.none,
          ),
          validator: (value) {
            if (value!.trim().isEmpty) {
              return '学历性质不能为空';
            } else if (value.trim().length > 15) {
              return '学历性质超出最大长度';
            } else {
              return null;
            }
          },
        ),
        decoration: BoxDecoration(
          border: Border.all(color: Colors.black26, width: 1.0),
          borderRadius: BorderRadius.circular(5.0),
        ),
      ),
    );

    var school = Padding(
      padding: const EdgeInsets.fromLTRB(64, 0, 64, 32),
      child: Container(
        padding: const EdgeInsets.symmetric(horizontal: 16),
        child: TextFormField(
          autofocus: true,
          decoration: const InputDecoration(
            labelText: '毕业院校',
            hintText: '您的毕业院校',
            border: InputBorder.none,
          ),
          validator: (value) {
            if (value!.trim().isEmpty) {
              return '毕业院校不能为空';
            } else if (value.trim().length > 20) {
              return '毕业院校超出最大长度';
            } else {
              return null;
            }
          },
        ),
        decoration: BoxDecoration(
          border: Border.all(color: Colors.black26, width: 1.0),
          borderRadius: BorderRadius.circular(5.0),
        ),
      ),
    );

    var academicMajor = Padding(
      padding: const EdgeInsets.fromLTRB(64, 0, 64, 32),
      child: Container(
        padding: const EdgeInsets.symmetric(horizontal: 16),
        child: TextFormField(
          autofocus: true,
          decoration: const InputDecoration(
            labelText: '所学专业',
            hintText: '您的所学专业',
            border: InputBorder.none,
          ),
          validator: (value) {
            if (value!.trim().isEmpty) {
              return '所学专业不能为空';
            } else if (value.trim().length > 10) {
              return '所学专业超出最大长度';
            } else {
              return null;
            }
          },
        ),
        decoration: BoxDecoration(
          border: Border.all(color: Colors.black26, width: 1.0),
          borderRadius: BorderRadius.circular(5.0),
        ),
      ),
    );

    var academicDegree = Padding(
      padding: const EdgeInsets.fromLTRB(64, 0, 64, 32),
      child: Container(
        padding: const EdgeInsets.symmetric(horizontal: 16),
        child: TextFormField(
          autofocus: true,
          decoration: const InputDecoration(
            labelText: '学历',
            hintText: '您的学历',
            border: InputBorder.none,
          ),
          validator: (value) {
            if (value!.trim().isEmpty) {
              return '学历不能为空';
            } else if (value.trim().length > 5) {
              return '学历超出最大长度';
            } else {
              return null;
            }
          },
        ),
        decoration: BoxDecoration(
          border: Border.all(color: Colors.black26, width: 1.0),
          borderRadius: BorderRadius.circular(5.0),
        ),
      ),
    );

    var academicMark = Padding(
      padding: const EdgeInsets.fromLTRB(64, 0, 64, 32),
      child: Container(
        padding: const EdgeInsets.symmetric(horizontal: 16),
        child: TextFormField(
          autofocus: true,
          decoration: const InputDecoration(
            labelText: '证书编号',
            hintText: '您的证书编号',
            border: InputBorder.none,
          ),
          validator: (value) {
            if (value!.trim().isEmpty) {
              return '证书编号不能为空';
            } else {
              return null;
            }
          },
        ),
        decoration: BoxDecoration(
          border: Border.all(color: Colors.black26, width: 1.0),
          borderRadius: BorderRadius.circular(5.0),
        ),
      ),
    );

    var bt_commit = Padding(
      padding: EdgeInsets.fromLTRB(64, 0, 64, 32),
      child: BaseButton(
        radius: 12,
        onTap: () {
          if ((_formKey.currentState as FormState).validate())
            validatePassed(context);
        },
        child: Text(
          '完成',
          style: TextStyle(
            fontSize: 16,
            color: Colors.white,
          ),
        ),
      ),
    );

    return Scaffold(
      appBar: AppBar(
        title: const Text('添加学历信息'),
      ),
      body: Scrollbar(
        child: SingleChildScrollView(
          child: Form(
            key: _formKey,
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.stretch,
              children: [
                graduationTime,
                academicPrograms,
                academicLevel,
                academicNature,
                school,
                academicMajor,
                academicDegree,
                academicMark,
                bt_commit,
              ],
            ),
          ),
        ),
      ),
    );
  }

  void validatePassed(BuildContext context) async {
    Timer(Duration(milliseconds: 500), (){
      Fluttertoast.showToast(msg: '提交成功');
      Navigator.pop(context);
    });
  }
}